/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


function Logger(){

    //匿名ユーザのuid
    this.anoymous_uid = 0;

    this.mouseover_cells_log_type = 1;
    this.click_bookinfo_log_type = 2;
    this.click_cells_log_type = 3;
    this.search_log_log_type = 4;
    this.change_axis_log_type = 5;
    this.slide_axis_log_type = 6;
    this.move_center_cells_log_type = 7;


    this.mouseover_cells_log = function(asin_info_id){
        data = {
            "asin_info_id":asin_info_id
        };
        ConnectToServerByMouseOverCellsLog = function(logid,data){
            var send_data = new Object();
            send_data['asin_info_id'] = data.asin_info_id;
            send_data['log_id'] = logid;
            //ユーザIDはセッションから取得
            jQuery.ajax({
                type: "GET",
                url: settings.url + "top/mouseover_cells_log",
                async: true,
                data: send_data,
                success: function(data){
                //ログの保存なので何もしない
                }
            });
        }
        this.ConnectToServerBySendLog(this.mouseover_cells_log_type,ConnectToServerByMouseOverCellsLog,data);
    };

    this.click_bookinfo_log = function(asin_info_id){
        data = {
            "asin_info_id":asin_info_id
        };
        ConnectToServerByMouseOverCellsLog = function(logid,data){
            var send_data = new Object();
            send_data['asin_info_id'] = data.asin_info_id;
            send_data['log_id'] = logid;
            //ユーザIDはセッションから取得
            jQuery.ajax({
                type: "GET",
                url: settings.url + "top/click_bookinfo_log",
                async: true,
                data: send_data,
                success: function(data){
                //ログの保存なので何もしない
                }
            });
        }
        this.ConnectToServerBySendLog(this.click_bookinfo_log_type,ConnectToServerByMouseOverCellsLog,data);
    };

    this.click_cells_log = function(asin_info_id){
        data = {
            "asin_info_id":asin_info_id
        };
        ConnectToServerByMouseOverCellsLog = function(logid,data){
            var send_data = new Object();
            send_data['asin_info_id'] = data.asin_info_id;
            send_data['log_id'] = logid;
            //ユーザIDはセッションから取得
            jQuery.ajax({
                type: "GET",
                url: settings.url + "top/click_cells_log",
                async: true,
                data: send_data,
                success: function(data){
                //ログの保存なので何もしない
                }
            });
        }
        this.ConnectToServerBySendLog(this.mouseover_cells_log_type,ConnectToServerByMouseOverCellsLog,data);
    };

    this.search_log = function(query){
        data = {
            "query":query
        };
        ConnectToServerByMouseOverCellsLog = function(logid,data){
            var send_data = new Object();
            send_data['query'] = data.query;
            send_data['log_id'] = logid;
            //ユーザIDはセッションから取得
            jQuery.ajax({
                type: "GET",
                url: settings.url + "top/search_log",
                async: true,
                data: send_data,
                success: function(data){
                //ログの保存なので何もしない
                }
            });
        }
        this.ConnectToServerBySendLog(this.search_log_log_type,ConnectToServerByMouseOverCellsLog,data);
    };

    this.change_axis_log = function(axis_id,asin_infos_id,log_array){
        data = {
            "axis_id":axis_id,
	    "asin_infos_id":asin_infos_id,
	    "axis_combination":log_array.join("_")
        };
        ConnectToServerByMouseOverCellsLog = function(logid,data){
            var send_data = new Object();
            send_data['axis_id'] = data.axis_id;
	    send_data['axis_combination'] = data.axis_combination;
            send_data['log_id'] = logid;
            //ユーザIDはセッションから取得
            jQuery.ajax({
                type: "GET",
                url: settings.url + "top/change_axis_log",
                async: true,
                data: send_data,
                success: function(data){
                //ログの保存なので何もしない
                }
            });
	    logger.move_center_cells_log(logid,data.asin_infos_id);
        };
        this.ConnectToServerBySendLog(this.change_axis_log_type,ConnectToServerByMouseOverCellsLog,data);
    };

    this.slide_axis_log = function(axis_id,direction,asin_infos_id){
        data = {
            "axis_id":axis_id,
            "direction":direction,
	    "asin_infos_id":asin_infos_id
        };
        ConnectToServerByMouseOverCellsLog = function(logid,data){
            var send_data = new Object();
            send_data['axis_id'] = data.axis_id;
            send_data['direction'] = data.direction;
            send_data['log_id'] = logid;
            //ユーザIDはセッションから取得
            jQuery.ajax({
                type: "GET",
                url: settings.url + "top/slide_axis_log",
                async: true,
                data: send_data,
                success: function(data){
                //ログの保存なので何もしない
                }
            });
	    logger.move_center_cells_log(logid,data.asin_infos_id);
        };
        this.ConnectToServerBySendLog(this.slide_axis_log_type,ConnectToServerByMouseOverCellsLog,data);
    };

    //Loggerの中から呼ばれる
    this.move_center_cells_log = function(logid,asin_infos_id){
        var send_data = new Object();
        send_data['asin_infos_id'] = data.asin_infos_id;
	send_data['log_id'] = logid;
        //ユーザIDはセッションから取得
        jQuery.ajax({
			type: "GET",
			url: settings.url + "top/move_center_cells_log",
			async: true,
			data: send_data,
			success: function(data, dataType){
			    //ログの保存なので何もしない
			}
		    });	
    };


    //クリックログを保存する関数、Ajaxのラッパ
    this.ConnectToServerByClickLog = function(contents_id){
        var send_data = new Object();
        send_data['cid'] = contents_id;
        var recieve_data = "";
        jQuery.ajax({
            type: "GET",
            url: settings.url + "top/click",
            async: true,
            data: send_data,
            dataType: "json",
            success: function(data, dataType){
            //通信が成功したときの処理
            //logを残すだけなので何もしない
            }
        });
    }


    //ログ情報の送信(logsテーブルに書き込まれる)  privateメソッド
    //ログを保存する関数、Ajaxのラッパ
    this.ConnectToServerBySendLog = function(log_type,func,data){
        var send_data = new Object();
        send_data['log_type'] = log_type;
        //ユーザIDはセッションから取得
        jQuery.ajax({
            type: "GET",
            url: settings.url + "top/log",
            async: true,
            data: send_data,
            success: function(logid){
                //logidで本来のsend
                func(logid,data);
            }
        });
    }
}